import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
      { path: '/',redirect:'/login'},
    // { path: '/', name: 'test', component: () => import('../views/Test.vue'),},
    // { path: '/home', name: 'home', component: () => import('../views/Home.vue'),},
    // { path: '/test', name: 'test', component: () => import('../views/Test.vue'),},

    //嵌套路由(写子路由时不要写斜杠)---适用于做导航栏
    { path: '/manager',component: () => import('../views/Manager.vue'),children:[
        { path: 'home', name: 'home', meta:{ title:'主页'}, component: () => import('../views/Home.vue'),},
        { path: 'test', name: 'test', meta:{ title:'数控测试页面'}, component: () => import('../views/Test.vue'),},
        { path: 'data', name: 'data', meta:{ title:'数据展示你页面'}, component: () => import('../views/Data.vue'),},
        { path: 'employee', name: 'employee', meta:{ title:'员工消息'}, component: () => import('../views/Employee.vue'),},
        { path: 'admin', name: 'admin', meta:{ title:'管理员消息'}, component: () => import('../views/Admin.vue'),},
        { path: 'person', name: 'person', meta:{ title:'个人消息'}, component: () => import('../views/Person.vue'),},
        { path: 'password', name: 'password', meta:{ title:'修改密码'}, component: () => import('../views/Password.vue'),},
    ]},
    { path: '/login', name: 'login', meta:{ title:'登录页面'}, component: () => import('../views/Login.vue'),},
    { path: '/register', name: 'register', meta:{ title:'注册页面'}, component: () => import('../views/Register.vue'),},
    { path: '/404', name: '404', meta:{ title:'404找不到页面'}, component: () => import('../views/404.vue'),},
    { path :'/:pathMatch(.*)',redirect:'/404'} //表示如果没有被上面的路由匹配到的话就访问这个


  ],
})

// beforeEach 路由切换前的操作

// to：目标路由对象（跳转后的操作）。
// from：源路由对象（将要进行跳转的当前router对象）。
// next：必须调用的函数，控制导航流程：
router.beforeEach((to, from, next)=>{
    document.title = to.meta.title
    next()  //这个必须写，不然不能进去下一个钩子
})

export default router
